//
//  FmdbCell.m
//  OCDemo
//
//  Created by BH on 15/11/5.
//  Copyright © 2015年 baohan. All rights reserved.
//

#import "FmdbCell.h"

@interface FmdbCell()

@property (weak, nonatomic) IBOutlet UIButton *editBtn;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;
@property (weak, nonatomic) IBOutlet UIView *myContentView;
@property (weak, nonatomic) IBOutlet UILabel *myText;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentViewRightConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentViewLeftContraint;
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
@property (nonatomic, assign) CGPoint panStartPoint;
@property (nonatomic, assign) CGFloat startingRightLayoutConstraintConstant;

@end

static CGFloat const kBounceValue = 20.0f;

@implementation FmdbCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    self.panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panThisCell:)];
    self.panRecognizer.delegate = self;
    [self.myContentView addGestureRecognizer:self.panRecognizer];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//轻扫手势
-(void)panThisCell:(UIPanGestureRecognizer *)recognizer{

    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            self.panStartPoint = [recognizer translationInView:self.myContentView];
            self.startingRightLayoutConstraintConstant = self.contentViewRightConstraint.constant;
            break;
            
        case UIGestureRecognizerStateChanged:{
        
            CGPoint currentPoint = [recognizer translationInView:self.myContentView];
            CGFloat deltaX = currentPoint.x - self.panStartPoint.x;
            BOOL panningLeft = NO;  //是否左移
            if (currentPoint.x < self.panStartPoint.x) {
                panningLeft = YES;
            }
            
            if (self.startingRightLayoutConstraintConstant == 0) {
                
            }
        }
            break;
        case UIGestureRecognizerStateEnded:
            break;
        case UIGestureRecognizerStateCancelled:
            break;
            
        default:
            break;
    }
}

- (IBAction)btnClick:(id)sender {
    
    if (sender == self.editBtn) {
        [self.delegate clickEditButtonWithItemText:self.itemText];
    }else if (sender == self.deleteBtn){
    
        [self.delegate clickDeleteButtonWithItemText:self.itemText];
    }else{
    
        NSLog(@"Click unknown btn");
    }
}

-(void)setItemText:(NSString *)itemText
{
    _itemText = itemText;
    
    self.myText.text = itemText;
}

@end
